package com.example.tetris.beans;

import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.window.dialog.CommonDialog;
import ohos.app.Context;

public class MyCommondialog {
    CommonDialog commonDialog;
    public MyCommondialog(Context context,Component component) {
        //自定义弹框
        //1.创建弹框对象，大小是默认包裹内容的（match-content）,默认居中放置,默认透明的，默认直角
        commonDialog = new CommonDialog(context);
        //直角设置为圆角
        commonDialog.setCornerRadius(50);
        //设置高度为自适应,宽度为屏幕的0.8
        commonDialog.setSize(context.getResourceManager().getDeviceCapability().width
                * context.getResourceManager().getDeviceCapability().screenDensity
                / 160*7/8, ComponentContainer.LayoutConfig.MATCH_CONTENT);

        //自动关闭
        commonDialog.setAutoClosable(true);
        //此时布局对象跟弹框还没有关系，还需要把布局对象交给弹框
        commonDialog.setContentCustomComponent(component);
        //让弹框展示出来
        commonDialog.show();
    }
    public  void destroy(){
        commonDialog.destroy();
    }

}
